<extend name="Public:innerbase" />
<block name="css">
<link rel="stylesheet" href="{:STATICS}/validation/css/validationEngine.jquery.css">
</block>
<block name="js">
<include file="Public:upload" />
<include file="Public:editor" />
<script type="text/javascript" src="{:STATICS}/validation/js/jquery.validationEngine.js"></script>
<script type="text/javascript" src="{:STATICS}/validation/js/jquery.validationEngine-zh_CN.js"></script>
<script>
function showChildCats(value){
	$("#catid").html('<option value="0">请选择...</option>');
	if(value==0){
		document.getElementById('catid').disabled=true;
	}else{
		$.ajax({
			url: $('#catUrl').attr("value")+'&parentid='+value,
			success: function( data ) {
				document.getElementById('catid').disabled=false;
				$("#catid").html($("#catid").html()+data);
			}
		});
	}
}

function toDecimal(x) {  
	var f = parseFloat(x);  
	if (isNaN(f)) {  
		return;  
	}  
	f = Math.round(x*10)/10;  
	return f;  
}

function calDiscount(){
	var price=$('#price').attr('value');
	var oprice=$('#oprice').attr('value');
	if(oprice!=0&&oprice!=''){
		var dis=oprice-price;
		var discount=10-toDecimal((dis/oprice)*10);
	}else{
		discount=10;
	}
	$('#discount').attr('value',discount);
}
$(function(){
	$("#editForm").validationEngine("attach",{ 
		promptPosition:"centerRight",
		scroll:true,
		showOneMessage:true
	});
});
</script>
</block>
<block name="content">
<div class="container-fluid">
	<div class="page-header wm-page-header">
		<h4>菜品设置</h4>
		<a href="{:U('Dining/index')}" class="btn btn-default btn-sm">
			<span class="glyphicon glyphicon-chevron-left"></span>&nbsp;返回
		</a>
	</div>
	<form id="editForm" class="form-horizontal" method="post">
		<input type="hidden" name="id" value="{$set.id}" />
		<input type="hidden" name="discount" id="discount" value="{$set.discount}" />
		<div class="form-group">
			<label class="col-sm-2">名称</label>
			<div class="col-md-3">
				<input type="text" name="name" value="{$set.name}" class="form-control validate[required,maxSize[16]]" />
				<span class="help-block">菜品名称，不要超过16个字符</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2">分类</label>
			<div class="col-md-2">
				<select id="catid" name="catid" class="form-control">
					<option value="0">请选择分类...</option>
					{$catsOptions}
				</select>
			</div>
		</div>
		<div class="form-group" style="display:none;">
			<label class="col-sm-2">店铺</label>
			<div class="col-md-4">
				<input type="text" name="storeid" value="{$set.name}" class="form-control" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2">价格</label>
			<div class="col-md-2">
				<div class="input-group">
					<input type="text" id="price" onchange="calDiscount();" name="price" value="{$set.price}" class="form-control validate[required,custom[number]]" />
					<span class="input-group-addon">元</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2">原价</label>
			<div class="col-md-2">
				<div class="input-group">
					<input type="text" id="oprice" onchange="calDiscount();" name="oprice" value="{$set.oprice}" class="form-control validate[required,custom[number]]" />
					<span class="input-group-addon">元</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2">菜品图片</label>
			<div class="col-sm-6" >
				<input type="hidden" class="form-control" value="{$set.logourl}" id="img" name="logourl" />
				<img id="imgHolder" style="width:216px;height:120px;" class="img-rounded" <if condition="$set['logourl'] eq ''">src="{:RES}/images/photo/noneimg.jpg"</if> src="{$set.logourl}"/>
				<div class="btn-group" style="vertical-align:bottom;">
					<span class="btn btn-xs btn-primary" onclick="selectAsset('img',720,400)">
						<span class="glyphicon glyphicon-cloud-upload"></span>选择
					</span>
					<span class="btn btn-primary btn-xs" onclick="previewImg('img')">
						<span class="glyphicon glyphicon-picture"></span>预览
					</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2">菜品详细介绍</label>
			<div class="col-md-6">
				<textarea class="form-control" name="intro" id="content" rows="5" style="height:260px">{$set.intro}</textarea>
			</div>
		</div>
		<div class="form-group">
            <label class="col-sm-2">推荐指数</label>
            <div class="col-md-2">
                <input type="text" id="stars" name="stars" value="{$set.stars|default=1}" class="form-control validate[required,custom[integer],min[1],max[5]]" />
                <span class="help-block">范围1-5，越大越靠前</span>
            </div>
        </div>
		<div class="form-group">
            <label class="col-sm-2">是否上线</label>
            <div class="col-md-2">
				<label class="radio-inline">
					<input type="radio" name="status" value="1" <if condition="$set eq '' or $set['status'] eq 1">checked</if>>是
				</label>
				<label class="radio-inline">
					<input type="radio" name="status" value="0" <eq name="set['status']" value="0">checked</eq>/>否
				</label>
                <span class="help-block">控制手机上是否显示菜品</span>
            </div>
        </div>
		<div class="form-group">
            <label class="col-sm-2">排序</label>
            <div class="col-md-2">
                <input type="text" id="sort" name="sort" value="{$set.sort|default=1}" class="form-control validate[required,custom[integer],min[1],max[255]" />
                <span class="help-block">范围1-255，越小越靠前</span>
            </div>
        </div>
		<div class="form-group">
			<div class="col-md-5 col-sm-offset-2">
				<input type="submit" class="btn btn-primary" value="保存" />
			</div>
		</div>
	</form>
</div>
</block>